package main

import (
	"fmt"
	// "io/ioutil"
	"log"
	"net/http"
	"net/url"
)

func HelloServer(w http.ResponseWriter, req *http.Request) {
	// req.ParseForm()

	/*fmt.Printf("Request Method = ", req.Method)
	result, _ := ioutil.ReadAll(req.Body)
	req.Body.Close()
	fmt.Printf("%s\n", result)*/

	//取出参数
	queryForm, err := url.ParseQuery(req.URL.RawQuery)
	var requestParam string = ""
	if err == nil && len(queryForm["name"]) > 0 {
		requestParam = queryForm["name"][0]
		fmt.Printf("requestParam = ", requestParam)
	}
	fmt.Fprintf(w, "Hello, "+requestParam)
}

func main() {
	http.HandleFunc("/post", HelloServer)
	err := http.ListenAndServe("127.0.0.1:8082", nil)
	if err != nil {
		log.Fatal("ListenAndServe ", err.Error)
	}
}
